package com.xtone.pm.detector;

import java.text.SimpleDateFormat;
import java.util.Calendar;


public abstract class Detector {
	
	public static long interval=10*60*1000;//分钟
	
	public abstract String detect()throws Exception;
	
	public String dafaultDetect(String url,String pf)throws Exception{
		Calendar calendar=Calendar.getInstance();
		int h=calendar.get(Calendar.HOUR_OF_DAY);
		if(h>6 && h<23){
			String result=getMethod(url);
			String [] results=result.split(";");
			String last=results[1];
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			long lastRecord=sdf.parse(last).getTime();
			long now=System.currentTimeMillis();
			long delay=now-lastRecord;
			System.out.println("last:"+lastRecord);
			System.out.println("nsow:"+now);
			System.out.println("delay:"+delay);
			System.out.println(delay/60000);
			if(delay>interval){
				return pf+"已经超过"+delay/60000+"分钟没有计费数据，最近一条计费数据时间为："+last+"，请马上检查平台运行状态";
			}
		}
		return "success";
	}
	
	public String getMethod(String url)throws Exception{
		return URLConnectionUtil.doGet(url, null);
	}
}
